<template>
  <a-tree
    v-if="treeData.length > 0"
    :tree-data="treeData"
    :replaceFields="treeFields"
    :defaultExpandedKeys="[treeData[0].id]"
    :selected-keys="[chenken]"
    @select="onSelect"
  >
    <template slot="nodes" slot-scope="item">
      <span class="iconfont2" v-if="item.deptType == 0">&#xe600;</span>
      <span class="iconfont2" v-if="item.deptType == 1">&#xe629;</span>
      <span class="iconfont2" v-if="item.deptType == 2">&#xe664;</span>
      <span class="iconfont2" v-if="item.deptType == 3">&#xe64e;</span>
      <span class="iconfont2" v-if="item.deptType == 4">&#xe619;</span>
      <span class="iconfont2" v-if="item.deptType == 5">&#xe66b;</span>
      <span class="iconfont2" v-if="item.deptType == 6">&#xe777;</span>
      {{ item.title }}
    </template>
  </a-tree>
</template>
<script>
import { organizationTreeUser } from '@/api/system/organization'
import { mapGetters } from 'vuex'
export default {
  name: 'treeOrganization',
  computed: {
    ...mapGetters(['userInfo']),
  },
  props: {},
  data() {
    return {
      treeData: [], //组织机构
      treeFields: {
        children: 'children',
        title: 'title',
        key: 'id',
      },
      chenken: '0', //默认选中
    }
  },
  mounted() {
    this.getTree()
  },
  methods: {
    onSelect(selectedKeys, info) {
      if (selectedKeys.length == 0) {
        return
      }
      
      this.$emit('getTreeOne', info.node.dataRef)
      this.chenken = selectedKeys[0]
    },
    //查询当前角色组织机构
    getTree() {
      organizationTreeUser({
        roleIds: [],
      }).then((res) => {
        this.treeData = (res && res.children) || []
        this.$emit('getTreeOne', this.treeData[0] || {})
      })
    },
  },
}
</script>